package com.springBoot.controller;

public class ArrayFind {
    public static void main(String[] args) {
        int[] array1={1,2,3,4,5,5,6,6};
        int[] array2={4,5,6,8,9,10};
        int[] res=getIntersection(array1,array2);
        for (int arr : res) {
            System.out.print(arr+" ");
        }
    }

    private static int[] getIntersection(int[] aArray, int[] bArray){
        int size=0;
        for (int i : aArray) {
            for (int j : bArray) {
                if(i==j){
                    size++;
                }
            }
        }
        int[] res=new int[size];
        int index=0;
        for (int i : aArray) {
            for (int j : bArray) {
                if(i==j){
                    res[index]=j;
                    index++;
                }
            }
        }

        return getSigle(res);
    }
    //去重
    private static int[] getSigle(int[] arr){
        int slow=0;
        for (int fast = 1; fast < arr.length; fast++) {
            if (arr[slow]!=arr[fast]){
                slow++;
                arr[slow]=arr[fast];
            }
        }
        int[] newArr=new int[slow+1];
        for (int i = 0; i < slow+1; i++) {
            newArr[i]=arr[i];
        }
        return newArr;
    }
}
